package com.enation.app.shop.front.policyInsurance.service.impl;

import com.enation.app.shop.front.policyInsurance.entity.InsuranceFile;
import com.enation.app.shop.front.policyInsurance.service.InsuranceFileMapper;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("insuranceFileService")
public class InsuranceFileService implements InsuranceFileMapper{
    @Autowired
    private IDaoSupport daoSupport;
    @Override
    public int deleteByPrimaryKey(Long id) {
        String sql="delete from rbt_insurance_file where id=?";
        this.daoSupport.execute(sql,id);
        return 1;
    }

    @Override
    public int insert(InsuranceFile record) {
        this.daoSupport.insert("rbt_insurance_file",record);
        return 1;
    }

    @Override
    public int insertSelective(InsuranceFile record) {
        return 0;
    }

    @Override
    public InsuranceFile selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(InsuranceFile record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(InsuranceFile record) {
        this.daoSupport.update("",record,"id="+record.getId());
        return 1;
    }

    @Override
    public List<InsuranceFile> getBytype(Integer type1, Integer type2, Integer relevance_id) {
        if (type2==null){
            String sql="select * from rbt_insurance_file  where type1=?  and relevance_id=?";
            return this.daoSupport.queryForList(sql,InsuranceFile.class,type1,relevance_id);
        }
        String sql="select * from rbt_insurance_file  where type1=? and type2=? and relevance_id=?";
        return this.daoSupport.queryForList(sql,InsuranceFile.class,type1,type2,relevance_id);
    }

    @Override
    public List<InsuranceFile> getByInPolicyId(Integer inPolicy_id) {
        String sql = "SELECT s.url from rbt_insurance_file s where s.relevance_id=?";
        return daoSupport.queryForList(sql,InsuranceFile.class,inPolicy_id);
    }
}
